// create by dplord at 2017-02-06 16:37

#include <iostream>
#include "unistd.h"
#include "pthread.h"

using namespace std;


void* thread_main(void* arg) {
    int num = *((int *)arg);
    cout << num << "\n";

    delete arg;
    return NULL;
}

int main(int argc, char **argv) {
    for (int i = 0; i < 10; ++i) {
        int* a = new int;
        printf("%x \n", a);
        *a = i;

        pthread_t tid;
        if(pthread_create(&tid, NULL, thread_main, (void *) a) != 0) {
            printf("thread create error");
        }
    }

    //给线程函数留下足够的运行时间
    sleep(2);
    return 0;
}